<div id="profile-grid">
        <span class="page-heading">Profile</span>
        <?php 
				echo '<script type="text/javascript"> var base_url="' . base_url() . '";</script>';
				if($edit == true){
                        echo form_open('profile/'.$profile['fb_id'], array('id' => 'profile-form'));
                }
        ?>
        <div id="profile-details">
                <div id="facebook-pic"><a href="https://www.facebook.com/<?php echo $profile['fb_id']; ?>" target="_blank"><span class="get-fb-pic-large"><?php echo $profile['fb_id'] ?></span></a></div>
                <div id="facebook-info">
                <?php
                        echo '<span class="medium-text"><a href="https://www.facebook.com/' . $profile['fb_id'] . '" target="_blank"><span class="get-fb-name">' . $profile['fb_id'] . '</span></a></span><br /><br />';
                        echo '<span class="medium-text">Email: ' . $profile['email'] .'</span><br />';
                        if($edit == true){
								
								echo form_label("About Myself: ", "other_information", array('class' => 'normal-text')) . '<br />';
                                $attribute = array(
                                        'name'  => 'other_information',
                                        'id'    => 'other_information',
                                        'value' => $profile['other'],
										'placeholder' => 'Something about Yourself!',
                                );
                                echo form_textarea($attribute) . '<br />';
                        }
                        else{
                                echo '<label class="normal-text">About Myself: </label><br />';
                                echo '<div class="normal-text" id="other_information">' .$profile['other'] . '</div><br />';
                        }
                        
                        echo '<div id="stats">';
                                echo '<div id="offers"><span class="medium-text">Successful Offers<br />'.$successful_offers.'</span></br ></div>';
                                echo '<div id="vertical-bar"></div>';
                                echo '<div id="requests"><span class="medium-text">Successful Requests<br />'.$successful_requests.'</span></br ></div>';
                                echo '<div style="clear:both"></div>';
                        echo '</div><br />';            
                ?>
                </div>
                <div style="clear:both"></div><br />
        </div>
        <div class="horizontal-bar"></div>
		<div id="own-offers">
		<?php
			echo '<span class="page-subheading">My Offers</span><br />';
			echo '<div id="offers-container">';
				echo '<span class="control" id="leftControl">left</span>';
				echo '<div class="slide-container">';
						$i = 0;
						if(count($offers) == 0){
							echo '<div class="slide">';
							echo '<br /><span class="medium-text">No offers yet!</span>';
							echo '</div>';
						}
						
						foreach($offers as $o){
							if($i % 7 == 0){
								echo '<div class="slide">';
							}
							
							echo '<div class="padding"><div class="img-container"><a href="' . base_url('/itemdescription/' . $o['offer_id']) . '"><img class="resize-100" src="' . base_url('resources/offer_images_thumbnail/' . $o['item_pic']) . '" title="'.$o['item_title'].'"/></a></div></div>';
							
							if($i % 7 == 6){
								echo '</div>';
							}
							$i++;
						}
						if($i % 7 != 0){
							echo '</div>';
						}
				echo '</div>';
				echo '<span class="control" id="rightControl">right</span>';
			echo '</div>';
		?>
		</div>		
        <div class="horizontal-bar"></div>
		<?php
			if ($edit == true) {
				echo '<div id="notification-container">';
				echo '<span class="page-subheading">Email Prefences</span><br />';
				
				// Newsletter frequency selection
				echo '<div id="email-left">';
				echo form_label("Send me an email... ", "newsletter_day", array('class' => 'normal-text')) . '<br />';
				$newsletter_day_values = array (0, 1, 3, 7, 14);
				$newsletter_day_texts = array ('None', 'Every Day', 'Every 3 Days', 'Weekly', 'Fortnightly');
				for ($i = 0; $i < count($newsletter_day_values); ++$i) {
					if ($profile['newsletter_day'] == $newsletter_day_values[$i]) {
						echo '<input type="radio" name="newsletter_day" value="' . $newsletter_day_values[$i] .'" checked="checked" />' .
								$newsletter_day_texts[$i] . '<br />' ;
					} else { 
						echo '<input type="radio" name="newsletter_day" value="' . $newsletter_day_values[$i] .'" />' .
								$newsletter_day_texts[$i] . '<br />' ;
					}
				}
				echo '</div>';
				
				// Newsletter option selection
				echo '<div id="email-right">';
				echo form_label("To inform me know when there are... ", "newsletter_option", array('class' => 'normal-text')) . '<br />';
				$newsletter_option_values = array (1, 2, 3, 4);
				$newsletter_option_match = array ('new_offer', 'new_request', 'new_comment', 'new_notification'); 
				$newsletter_option_texts = array ('New Offers in The Trove', 'New Requests for my Offers', 
												'New Comments for my Offers', 'New Notifications from The Trove');
				for ($i = 0; $i < count($newsletter_option_values); ++$i) {
					if ($profile[$newsletter_option_match[$i]] == true) {
						echo '<input type="checkbox" name="newsletter_option[]" value="' . $newsletter_option_values[$i] .'" checked="checked" />' .
								$newsletter_option_texts[$i] . '<br />' ;
					} else { 
						echo '<input type="checkbox" name="newsletter_option[]" value="' . $newsletter_option_values[$i] .'" />' .
								$newsletter_option_texts[$i] . '<br />' ;
					}
				}/*
				echo '<input type="checkbox" name="newsletter_option[]" value="1" checked="checked" /> New Offers in The Trove<br />
					  <input type="checkbox" name="newsletter_option[]" value="2" checked="checked" /> New Requests for my Offers <br />
					  <input type="checkbox" name="newsletter_option[]" value="3" checked="checked" /> New Comments for my Offers <br />
					  <input type="checkbox" name="newsletter_option[]" value="4" checked="checked" /> New Notifications from The Trove <br />';*/
				echo '</div>';
				echo '</div><div class="horizontal-bar"></div>';
			}
		?>
		
        <div id="preferences-container">
                <div id="category-preference">
                <?php
                        echo '<span class="page-subheading">Category Preferences</span><br />';
                        if($edit == true){
                                // Add category reference
								$json_category_preference = json_encode($profile['category_preference']);
								echo '<script type="text/javascript"> var category_preference=' . $json_category_preference . '; </script>';
								$json_category = json_encode($category);
								echo '<script type="text/javascript"> var categories=' . $json_category . '; </script>';
								echo '<input type="hidden" name="category_list" id="category_list">';
								echo '<select name="choose_category" id="choose_category" onchange="add_category()">' ;
                                foreach ($category as $cat) {
									echo "<option value ='" . $cat['category_id'] . "'>"
													. $cat['category_name'] .
										 "</option>" ;
                                }
                                echo '</select>' ;   
								echo '<div id="category_container"> </div>';
                                                  
                        }
                        else{
                                foreach ($profile['category_preference'] as $cat_ref) {
                                        echo '<span class="normal-text">-- '.$cat_ref['category_name'].'</span><br />';
                                }
                        }
                ?>
                </div>
                <div id="area-preference">
                <?php
                        echo '<span class="page-subheading">Area Preferences</span><br />';
                        if($edit == true){
                                // Add location reference
								$json_area_preference = json_encode($profile['area_preference']);
								echo '<script type="text/javascript"> var area_preference=' . $json_area_preference . '; </script>';
								$json_area = json_encode($area);
								echo '<script type="text/javascript"> var areas=' . $json_area .'; </script>';
								echo '<input type="hidden" name="area_list" id="area_list">';
								
                                echo '<select name="choose_area" id="choose_area" onchange="add_area()">' ;
                                foreach ($area_group as $group) {
                                        echo "<optgroup label=" . $group['area_group_name'] . ">" ;
                                        foreach ($area as $loc) {
                                                if ($loc['area_group_id'] == $group['area_group_id']) {
                                                        echo "<option value ='" . $loc['area_id'] . "'>"
                                                                        . $loc['area_name'] .
                                                             "</option>" ;
                                                }
                                        }                       
                                        echo "</optgroup>" ;
                                }
                                echo '</select>' ;
								echo '<div id="area_container"> </div>';
                        }
                        else{
                                foreach ($profile['area_preference'] as $a_ref) {
                                        echo '<span class="normal-text">-- '.$a_ref['area_name'].'</span><br />';
                                }
                        }
                ?>
                </div>
                <div style="clear:both"></div>
        </div>
		
		<?php
			if ($edit == true){
				echo '<div id="submit-button"><input type="image" src="'.base_url('/resources/profile/submit.gif') .'" name="save_button" alt="submit"></div>';
			}
		?>
		
		
		
		
</div>
<div style="height: 30px"></div>
<?php
        if ($edit == true) {
                echo form_close();
        }
?>
